Micron Document




Python (programming language)
part 28/106 · 174.3 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Python supports optional type annotations.cite-ref-type-hint-pep-5-1[5]cite-ref-102[99] These annotations are not enforced by the language, but may be used by external tools such as mypy to catch errors.cite-ref-103[100]cite-ref-104[101] Mypy also supports a Python compiler called mypyc, which leverages type annotations for optimization.cite-ref-105[102]

| Type | Mutability | Description | Syntax examples |
|---|---|---|---|
| bool | immutable | Boolean value | True False |
| bytearray | mutable | Sequence of bytes | bytearray ( b 'Some ASCII' ) bytearray ( b "Some ASCII" ) bytearray ([ 119 , 105 , 107 , 105 ]) |
| bytes | immutable | Sequence of bytes | b 'Some ASCII' b "Some ASCII" bytes ([ 119 , 105 , 107 , 105 ]) |
| complex | immutable | Complex number with real and imaginary parts | 3 + 2.7 j 3 + 2.7 j |
| dict | mutable | Associative array (or dictionary) of key and value pairs; can contain mixed types (keys and values); keys must be a hashable type | { 'key1' : 1.0 , 3 : False } {} |
| types.EllipsisType | immutable | An ellipsis placeholder to be used as an index in NumPy arrays | ... Ellipsis |
| float | immutable | Double-precision floating-point number . The precision is machine-dependent, but in practice it is generally implemented as a 64-bit IEEE 754 number with 53 bits of precision. [ 103 ] | 1.33333 |
| frozenset | immutable | Unordered set , contains no duplicates; can contain mixed types, if hashable | frozenset ([ 4.0 , 'string' , True ]) |
| int | immutable | Integer of unlimited magnitude [ 104 ] | 42 |
| list | mutable | List , can contain mixed types | [ 4.0 , 'string' , True ] [] |
| types.NoneType | immutable | An object representing the absence of a value, often called null in other languages | None |
| types.NotImplementedType | immutable | A placeholder that can be returned from overloaded operators to indicate unsupported operand types. | NotImplemented |
| range | immutable | An immutable sequence of numbers, commonly used for iterating a specific number of times in for loops [ 105 ] | range ( − 1 , 10 ) range ( 10 , − 5 , − 2 ) |
| set | mutable | Unordered set , contains no duplicates; can contain mixed types, if hashable | { 4.0 , 'string' , True } set () |
| str | immutable | A character string : sequence of Unicode codepoints | 'Wikipedia' "Wikipedia" """Spanning multiple lines""" |
| tuple | immutable | Tuple , can contain mixed types | ( 4.0 , 'string' , True ) ( 'single element' ,) () |
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────